const mongoose = require('mongoose');

/**
 * 权限模型
 * 定义系统中的权限项
 */
const permissionSchema = new mongoose.Schema({
  // 权限代码，如 'create:product', 'read:user', 'update:order' 等
  code: {
    type: String,
    required: true,
    unique: true
  },
  
  // 权限名称，用于显示
  name: {
    type: String,
    required: true
  },
  
  // 权限描述
  description: {
    type: String,
    default: ''
  },
  
  // 权限分组，用于前端展示和管理，如 'product', 'user', 'order' 等
  group: {
    type: String,
    required: true
  }
}, {
  timestamps: true
});

const Permission = mongoose.model('Permission', permissionSchema);

module.exports = Permission; 